package com.like.miaosha.access;

import com.like.miaosha.domain.MiaoshaUser;

/**
 * @ClassName UserContext
 * @Description: TODO
 * @Author dongfengke
 * @Date 2022/1/18
 * @Version V1.0
 **/
public class UserContext {
    //把  accessLimit中获取的user信息保存到ThreadLocal中

    //ThreadLocal 是跟当前线程绑定的，在多线程中一种保存信息的方式
    private static ThreadLocal<MiaoshaUser> userHolder=new ThreadLocal<>();
    public static void setUser(MiaoshaUser user){
        userHolder.set(user);
    }
    public static MiaoshaUser getUser(){
        return userHolder.get();
    }
}
